package com.xindao.app;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public abstract class IFragment {

  private ViewGroup container;
  private int layout;

  public IFragment(ViewGroup content, int resId) {
    container = content;
    layout = resId;
  }

  public void reFillIn() {
    container.removeAllViews();
    LayoutInflater.from(container.getContext()).inflate(layout, container);
    fillIn(container);
  }

  protected abstract void fillIn(ViewGroup content);

  public abstract void onResume();

  public abstract void onPause();

  public abstract void onStop();

  public abstract void onDestroy();

  protected View id(int id) {
    return container.findViewById(id);
  }

  public void onResult(int requestCode, int resultCode, Intent data) {
  }

  protected Context context() {
    return container.getContext();
  }

  protected LayoutInflater inflater() {
    return LayoutInflater.from(context());
  }

  public void startActivity(Intent intent) {
    context().startActivity(intent);
  }

  public ViewGroup content() {
    return container;
  }

  public boolean onBackPressed() {
    return false;
  }

}
